package com.ruoyi.project.erp.controller;

import com.ruoyi.project.erp.domain.VersionPOJO;
import com.ruoyi.project.tool.APKUtils;
import lombok.extern.slf4j.Slf4j;
import net.dongliu.apk.parser.bean.ApkMeta;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;
import java.io.IOException;

@RestController
@Slf4j
@RequestMapping("/apk")
public class ApkUpdateController {

    @Value("${project.apkPath}")
    private String apkPath;
    @Value("${project.apkName}")
    private String apkName;
    @GetMapping("/mobileVer")
    public VersionPOJO getPhoneVer() throws IOException {
        String filePath = new File(apkPath + "/" + apkName).getAbsolutePath();
//        String filePath = apkPath +"\\"+ apkName;
        System.out.println("文件路径==============" + filePath);
        log.info("文件路径==============" + filePath);
        ApkMeta apkMeta = APKUtils.AnalysisAPK(filePath);
        if (null == apkMeta) {
            throw new RuntimeException("未发现可供下载的文件");
        }
        return new VersionPOJO(apkMeta.getPackageName(), 2, 100L, "http://49.7.230.17:5173/download/htWorkLogManage.apk");
    }
}
